﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Media3D;
using System.Windows.Markup;
using System.Windows.Media.Animation;

namespace CrazyClient
{
    /// <summary>
    /// Interaction logic for LyricPanel.xaml
    /// </summary>
    /// 
    [ContentProperty("Title")]
    public partial class LyricPanel : ModelVisual3D
    {

        #region IdProperty
        public static readonly DependencyProperty IdProperty =
            DependencyProperty.Register("Id", typeof(int),
            typeof(LyricPanel)
            );

        static private void OnIdChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
       //     TranslateTransform3D d = new TranslateTransform3D(0, 0, 0);
       ////     ((PerspectiveCamera)obj).Transform = d;
        //    d.BeginAnimation(TranslateTransform3D.OffsetXProperty, new DoubleAnimation(0, 1, new Duration(new TimeSpan(0, 0, 5))));
            //Debug.WriteLine("Mass property changed from {0} to {1}", e.OldValue, e.NewValue);
        }
        public int Id
        {
            get
            {
                object result = GetValue(IdProperty);
                return (int)result;
            }
            set
            {
                SetValue(IdProperty, value);
            }
        }
        
        #endregion


        #region LyricControlProperty
        public static readonly DependencyProperty LyricControlProperty =
            DependencyProperty.Register("LyricControl", typeof(int),
            typeof(LyricPanel),
            new PropertyMetadata(OnLyricControlChanged));

        static private void OnLyricControlChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            LyricPanel panel = obj as LyricPanel;

            if (panel.LyricControl == panel.Id)
                if (panel.TransitionIn != null)
                    panel.TransitionIn.Go();
                else
                {
                    DoubleAnimation anim = new DoubleAnimation(1, new Duration(new TimeSpan(0, 0, 0)));
                    panel.TheContent.BeginAnimation(VisualBrush.OpacityProperty, anim, HandoffBehavior.Compose);
                }
            else
            //panel. DoubleAnimation anim = new DoubleAnimation(1, new Duration(new TimeSpan(0, 0, 0)));
            {
                if (panel.TransitionOut!=null)
                {
                    panel.TransitionOut.Go();
                }
                else
                {
                    DoubleAnimation anim = new DoubleAnimation(0, new Duration(new TimeSpan(0, 0, 0)));
                    panel.TheContent.BeginAnimation(VisualBrush.OpacityProperty, anim, HandoffBehavior.Compose);
                }
            }

            //     TranslateTransform3D d = new TranslateTransform3D(0, 0, 0);
            ////     ((PerspectiveCamera)obj).Transform = d;
            //    d.BeginAnimation(TranslateTransform3D.OffsetXProperty, new DoubleAnimation(0, 1, new Duration(new TimeSpan(0, 0, 5))));
            //Debug.WriteLine("Mass property changed from {0} to {1}", e.OldValue, e.NewValue);
        }
     
        public int LyricControl{
            get
            {
                
                object result = GetValue(LyricControlProperty);
                return (int)result;
            }
            set
            {
                
               SetValue(LyricControlProperty, value);
            }
        }
       
        #endregion


        #region TransitionInProperty
        public static readonly DependencyProperty TransitionInProperty =
            DependencyProperty.Register("TransitionIn", typeof(ITransition),
            typeof(LyricPanel),
            new PropertyMetadata(OnTransitionInChanged));

        static private void OnTransitionInChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            //FadeIn panel = obj as FadeIn;
            //obj.Go()
            ((ITransition)e.NewValue).ParentPanel = (obj as LyricPanel);
            
            //     TranslateTransform3D d = new TranslateTransform3D(0, 0, 0);
            ////     ((PerspectiveCamera)obj).Transform = d;
            //    d.BeginAnimation(TranslateTransform3D.OffsetXProperty, new DoubleAnimation(0, 1, new Duration(new TimeSpan(0, 0, 5))));
            //Debug.WriteLine("Mass property changed from {0} to {1}", e.OldValue, e.NewValue);
        }

        public ITransition TransitionIn
        {
            get
            {
                object result = GetValue(TransitionInProperty);
                return (ITransition)result;
            }
            set
            {
                value.ParentPanel = this;
                SetValue(TransitionInProperty, value);
            }
        }

        #endregion


        #region TransitionOutProperty
        public static readonly DependencyProperty TransitionOutProperty =
            DependencyProperty.Register("TransitionOut", typeof(ITransition),
            typeof(LyricPanel),
            new PropertyMetadata(OnTransitionOutChanged));

        static private void OnTransitionOutChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            //FadeIn panel = obj as FadeIn;
            //obj.Go()
            ((ITransition)e.NewValue).ParentPanel = (obj as LyricPanel);

            //     TranslateTransform3D d = new TranslateTransform3D(0, 0, 0);
            ////     ((PerspectiveCamera)obj).Transform = d;
            //    d.BeginAnimation(TranslateTransform3D.OffsetXProperty, new DoubleAnimation(0, 1, new Duration(new TimeSpan(0, 0, 5))));
            //Debug.WriteLine("Mass property changed from {0} to {1}", e.OldValue, e.NewValue);
        }

        public ITransition TransitionOut
        {
            get
            {
                object result = GetValue(TransitionOutProperty);
                return (ITransition)result;
            }
            set
            {
                value.ParentPanel = this;
                SetValue(TransitionOutProperty, value);
            }
        }

        #endregion
        public LyricPanel()
        {
            InitializeComponent();
        }
        public Visual Title
        {
            get
            {
                return this.TheContent.Visual;
            }
            set
            {
                this.TheContent.Visual = value;
            }
        }

        #region INameScope Members

       
       
        FrameworkElement _parent;
        public FrameworkElement Parent
        {
            get
            {
                return _parent;
            }

        }
        public void SetParent(FrameworkElement p)
        {
            _parent = p;
        }
       
    

        #endregion
    }
}
